package FIT::Document;

use FIT::Class;
use FIT::Document::Transformer;
use aliased 'FIT::Document::Parser';

has [qw( in out )] => (is => 'ro', isa => 'Str', required => 1);

has parser => (
    is       => 'ro',
    isa      => 'FIT::Document::Parser',
    required => 1,
    lazy     => 1,
    handles  => [qw( first_table write in_dir out_dir out_file twig )],
    default  => sub { Parser->new( in => $_[0]->in, out => $_[0]->out ) },
);

sub in_file { $self->in }

sub BUILD { transform { AddSummaryTable } $self->first_table }


=head1 NAME

FIT::Document - a FIT test document


=head1 SYNOPSIS

    use aliased 'FIT::Document';

    my $document = Document->new(
        in  => "../eg/html/Division.html",
        out => "tmp", # can be a dir or a file with .html suffix
    );

    print $document->first_table->fixture_name; # FIT.eg.Division
    $document->write;
    # and other methods from FIT::Document::Parser


=head1 DESCRIPTION

You create a FIT test document with an input file and an output file or directory.

Then you can access the 1st table with C< first_table() >.

Use C< write() > to write the document to the output file or directory.

A FIT document automatically gets a summary table, appended as the last table.

=cut

